package com.snowleopard.findpeople.service.publish;

import java.util.List;

import org.apache.commons.lang.xwork.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import com.snowleopard.common.base.BaseDao;
import com.snowleopard.common.base.BaseServiceImpl;
import com.snowleopard.findpeople.dao.publish.InfoPublishDao;
import com.snowleopard.findpeople.entity.publish.InfoPublish;

@Service
@Transactional
public class InfoPublishManager extends BaseServiceImpl<InfoPublish, String> {
    

    @Autowired
    private InfoPublishDao infoPublishDao;

    
    @Override
    protected BaseDao<InfoPublish, String> getDao() {
        return infoPublishDao;
    }

    // InfoPublish Manager //
    @Transactional(readOnly = true)
    public InfoPublish getInfoPublish(String id) {
        return infoPublishDao.get(id);
    }

    @Transactional(readOnly = true)
    public List<InfoPublish> getAllInfoPublish() {
        return infoPublishDao.getAll();
    }

    public void saveInfoPublish(InfoPublish infoPublish) {

        if (StringUtils.isBlank(infoPublish.getId())) {
            infoPublishDao.save(infoPublish);
        } else {

            InfoPublish oldInfoPublish = infoPublishDao.get(infoPublish.getId());
            BeanUtils.copyProperties(infoPublish, oldInfoPublish, new String[] { "id", "createdBy",
                    "createdDate" });

            infoPublishDao.update(oldInfoPublish);
        }

    }

    public void deleteInfoPublish(String id) {
        infoPublishDao.delete(id);
    }

    /**
     * 使用属性过滤条件查询用户.
     */
    @Transactional(readOnly = true)
    public Page<InfoPublish> searchPublishInfoByCondition(final Page<InfoPublish> page,
            final List<PropertyFilter> filters) {
        return infoPublishDao.findPage(page, filters);
    }

    public Page<InfoPublish> searchPublishInfoByCondition(final Page<InfoPublish> page,
            InfoPublish infoPublish) {
        return infoPublishDao.findPage(page, infoPublish);
    }

}
